#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<unistd.h>
#include"process.h"

typedef void (*call_t)(const char*, double, double);

double total = 1024.0;
double speed[] = {1.0, 0.5, 0.3, 0.02, 0.01};

//模拟下载函数
void download(double total_size, call_t cb)
{
	srand(time(NULL));//初始化随机种子
	double current = 0.0;
	while(current <= total_size)
	{
		cb("下载中", total_size, current);//回调函数
		//moni 
		int random = rand() % 6;//dapei speed
		//下载代码
		usleep(5000);
		current += speed[random];
		//jindu daxiao
		if(current >=total_size)
		{
		current = total_size;
		break;
		}
	}
		
}

int main()
{
	download(1024.0, FlushProcess);
	printf("download 1024.0MB done\n");
	
	return 0;	
}

